package com.xf.system.controller;

import com.xf.system.common.facade.RoleFacade;
import com.xf.system.http.req.role.RoleAddReqDTO;
import com.xf.system.http.req.role.RoleChangeStatusReqDTO;
import com.xf.system.http.req.role.RoleListReqDTO;
import com.xf.system.http.req.role.RoleUpdateReqDTO;
import com.xf.system.http.vo.role.RoleDetailVO;
import com.xf.system.http.vo.role.RoleVO;
import com.xf.system.response.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author xiefengf
 * @date 2024/2/20 14:47
 * @version 1.0
 */
@Api(tags = "角色服务Api")
@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleFacade roleFacade;

    @GetMapping("/listRoles")
    @Operation(summary = "根据条件分页查询角色列表",method = "GET")
    public ApiResult<RoleVO> listRoles(@ModelAttribute RoleListReqDTO reqDto) {
        RoleVO vo = roleFacade.listRoles(reqDto);
        return ApiResult.success(vo);
    }

    @GetMapping("/getRoleById/{id}")
    @Operation(summary = "通过角色id查询角色详情信息",method = "GET")
    public ApiResult<RoleDetailVO> getRoleById(@PathVariable(value = "id") Long id) {
        RoleDetailVO vo = roleFacade.getRoleById(id);
        return ApiResult.success(vo);
    }

    @PostMapping("/saveRole")
    @Operation(summary = "新增角色信息",method = "POST")
    public ApiResult<Boolean> saveRole(@RequestBody @Valid RoleAddReqDTO reqDto) {
        Boolean aBoolean = roleFacade.saveRole(reqDto);
        return ApiResult.success(aBoolean);
    }

    @PutMapping("/updateRole")
    @Operation(summary = "更新角色信息",method = "PUT")
    public ApiResult<Boolean> updateRole(@RequestBody @Valid RoleUpdateReqDTO reqDto) {
        Boolean aBoolean = roleFacade.updateRole(reqDto);
        return ApiResult.success(aBoolean);
    }

    @DeleteMapping("/deleteRole/{idList}")
    @Operation(summary = "批量删除角色信息",method = "DELETE")
    public ApiResult<Boolean> deleteRole(@PathVariable(value = "idList") Long[] idList) {
        Boolean aBoolean = roleFacade.deleteRole(idList);
        return ApiResult.success(aBoolean);
    }

    @PutMapping("/changeStatus")
    @Operation(summary = "角色状态修改",method = "PUT")
    public ApiResult<Boolean> changeStatus(@RequestBody @Valid RoleChangeStatusReqDTO reqDto) {
        Boolean aBoolean = roleFacade.changeStatus(reqDto);
        return ApiResult.success(aBoolean);
    }


}
